﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using CMISLibrary;
using BCNPCObject;
using BCNPCObject.DB;
using System.Data.OracleClient;
using System.Windows;
using System.Windows.Forms;
namespace bus_TienichNPC
{
    public class cls_NPC_TRTH_DDO
    {
        #region   Atributes

        private cls_NPC_TRTH_DDO_Controller obj_NPC_TRTH_DDO_Controller;
        private NPC_TRTH_DDO obj_NPC_TRTH_DDO_Info;

        #endregion


        #region   Constructor

        
        public cls_NPC_TRTH_DDO()
        {
            obj_NPC_TRTH_DDO_Info = new NPC_TRTH_DDO();
            obj_NPC_TRTH_DDO_Controller = new cls_NPC_TRTH_DDO_Controller();
        }
        public cls_NPC_TRTH_DDO(DataSet entity)
        {
            obj_NPC_TRTH_DDO_Info = new NPC_TRTH_DDO();
            obj_NPC_TRTH_DDO_Controller = new cls_NPC_TRTH_DDO_Controller();
        }       

        #endregion

        #region Method

        public DataSet select_NPC_TRTH_DDO_All(string strMadviqly)
        {
            try
            {
                if (obj_NPC_TRTH_DDO_Controller == null)
                {
                    obj_NPC_TRTH_DDO_Controller = new cls_NPC_TRTH_DDO_Controller();
                }

                var q = from p in obj_NPC_TRTH_DDO_Controller.select_NPC_TRTH_DDO_All(strMadviqly)
                        select new
                        {
                            p.ID_TRTH,
                            p.MA_DVIQLY,
                            p.MA_DDO,
                            p.SO_CTO,
                            p.MA_CTO,
                            p.MA_LDO,
                            p.BCS,
                            p.TG_CANCU,
                            p.TG_TRTH,
                            p.SL_CANCU,
                            p.SL_TRTHU,
                            p.SL_THAO,
                            p.NGAYTRTH_TU,
                            p.GIOTRHU_TU,
                            p.PHUTTRHU_TU,
                            p.NGAYTRTH_DEN,
                            p.GIOTRHU_DEN,
                            p.PHUTTRHU_DEN,
                            p.NGUOI_TAO,
                            p.NGAY_TAO,
                            p.TG_MDIEN_CANCU,
                            p.TG_MDIEN_TRTHU,
                            p.CHUOI_GIA,
                            p.THANH_TIEN,
                            p.THANH_TIEN_TRU_SLTHAO
                        };

                if (q != null && q.Count() > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(q);
                    dt.TableName = "NPC_TRTH_DDO";
                    dt.AcceptChanges();
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }

                return null;
            }
            catch
            {
                return null;
            }
        }

        public DataSet select_NPC_TRTH_DDO_by_id_truythu(long intID)
        {
            try
            {
                if (obj_NPC_TRTH_DDO_Controller == null)
                {
                    obj_NPC_TRTH_DDO_Controller = new cls_NPC_TRTH_DDO_Controller();
                }

                var a = obj_NPC_TRTH_DDO_Controller.select_NPC_TRTH_DDO_by_id_truythu(intID);

                var q = from p in a
                        select new 
                        {
                            p.ID_TRTH,
                            p.MA_DVIQLY,
                            p.MA_DDO,
                            p.SO_CTO,
                            p.MA_CTO,
                            p.MA_LDO,
                            p.BCS,
                            p.TG_CANCU,
                            p.TG_TRTH,
                            p.SL_CANCU,
                            p.SL_TRTHU,
                            p.SL_THAO,
                            p.NGAYTRTH_TU,
                            p.GIOTRHU_TU,
                            p.PHUTTRHU_TU,
                            p.NGAYTRTH_DEN,
                            p.GIOTRHU_DEN,
                            p.PHUTTRHU_DEN,
                            p.NGUOI_TAO,
                            p.NGAY_TAO,
                            p.TG_MDIEN_CANCU,
                            p.TG_MDIEN_TRTHU,
                            p.CHUOI_GIA,
                            p.THANH_TIEN,
                            p.THANH_TIEN_TRU_SLTHAO
                        };

                if (q != null && q.Count() > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(q);
                    dt.TableName = "NPC_TRTH_DDO";
                    dt.AcceptChanges();
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }

                return null;
            }
            catch
            {
                return null;
            }
        }

        public bool insert_NPC_TRTH_DDO(DataSet Entity, ref string strErr)
        {
            try
            {
                this.mapEntityToInfo(Entity);
                if (obj_NPC_TRTH_DDO_Controller == null)
                {
                    obj_NPC_TRTH_DDO_Controller = new cls_NPC_TRTH_DDO_Controller();
                }
                return obj_NPC_TRTH_DDO_Controller.insert_NPC_TRTH_DDO(ref strErr);
            }
            catch (Exception ex)
            {
                strErr = ex.Message;
                return false;
            }
        }

        public bool update_NPC_TRTH_DDO(DataSet Entity, ref string strErr)
        {
            try
            {
                this.mapEntityToInfo(Entity);
                if (obj_NPC_TRTH_DDO_Controller == null)
                {
                    obj_NPC_TRTH_DDO_Controller = new cls_NPC_TRTH_DDO_Controller();
                }
                return this.obj_NPC_TRTH_DDO_Controller.update_NPC_TRTH_DDO(ref strErr);
            }
            catch (Exception ex)
            {
                strErr = ex.Message;
                return false;
            }

        }

        public bool delete_NPC_TRTH_DDO(DataSet Entity, ref string strErr)
        {
            try
            {
                this.mapEntityToInfo(Entity);
                if (obj_NPC_TRTH_DDO_Controller == null)
                {
                    obj_NPC_TRTH_DDO_Controller = new cls_NPC_TRTH_DDO_Controller();
                }
                return this.obj_NPC_TRTH_DDO_Controller.delete_NPC_TRTH_DDO(ref strErr);
            }
            catch (Exception ex)
            {
                strErr = ex.Message;
                return false;
            }
        }
        

        public void mapEntityToInfo(DataSet Entity)
        {
            if (this.obj_NPC_TRTH_DDO_Controller == null)
            {
                this.obj_NPC_TRTH_DDO_Controller = new cls_NPC_TRTH_DDO_Controller();
            }            

            this.obj_NPC_TRTH_DDO_Controller.pInfor.MA_DVIQLY = Entity.Tables[0].Rows[0]["MA_DVIQLY"].ToString();
            this.obj_NPC_TRTH_DDO_Controller.pInfor.ID_TRTH = Convert.ToInt64(Entity.Tables[0].Rows[0]["ID_TRTH"]);
            this.obj_NPC_TRTH_DDO_Controller.pInfor.MA_DDO = Entity.Tables[0].Rows[0]["MA_DDO"].ToString();
            this.obj_NPC_TRTH_DDO_Controller.pInfor.SO_CTO = Entity.Tables[0].Rows[0]["SO_CTO"].ToString();
            this.obj_NPC_TRTH_DDO_Controller.pInfor.MA_CTO = Entity.Tables[0].Rows[0]["MA_CTO"].ToString();
            this.obj_NPC_TRTH_DDO_Controller.pInfor.MA_LDO = Entity.Tables[0].Rows[0]["MA_LDO"].ToString();
            this.obj_NPC_TRTH_DDO_Controller.pInfor.BCS = Entity.Tables[0].Rows[0]["BCS"].ToString();
            
            
            if(Entity.Tables[0].Rows[0]["TG_CANCU"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.TG_CANCU = Convert.ToDecimal(Entity.Tables[0].Rows[0]["TG_CANCU"]);
            }
            else
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.TG_CANCU = null;
            }

            if(Entity.Tables[0].Rows[0]["TG_TRTH"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.TG_TRTH = Convert.ToDecimal(Entity.Tables[0].Rows[0]["TG_TRTH"]);
            }
            else
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.TG_TRTH = null;
            }

            if(Entity.Tables[0].Rows[0]["SL_CANCU"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.SL_CANCU = Convert.ToDecimal(Entity.Tables[0].Rows[0]["SL_CANCU"]);
            }
            else
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.SL_CANCU = null;
            }

            if(Entity.Tables[0].Rows[0]["SL_TRTHU"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.SL_TRTHU = Convert.ToDecimal(Entity.Tables[0].Rows[0]["SL_TRTHU"]);
            }
            else
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.SL_TRTHU = null;
            }

            if(Entity.Tables[0].Rows[0]["SL_THAO"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.SL_THAO = Convert.ToDecimal(Entity.Tables[0].Rows[0]["SL_THAO"]);
            }
            else
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.SL_THAO = null;
            }

            if(Entity.Tables[0].Rows[0]["NGAYTRTH_TU"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.NGAYTRTH_TU = Convert.ToDateTime(Entity.Tables[0].Rows[0]["NGAYTRTH_TU"]);
            }
            else
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.NGAYTRTH_TU = null;
            }

            if(Entity.Tables[0].Rows[0]["GIOTRHU_TU"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.GIOTRHU_TU = Convert.ToInt16(Entity.Tables[0].Rows[0]["GIOTRHU_TU"]);
            }
            else
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.GIOTRHU_TU = null;
            }

            if(Entity.Tables[0].Rows[0]["PHUTTRHU_TU"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.PHUTTRHU_TU = Convert.ToInt16(Entity.Tables[0].Rows[0]["PHUTTRHU_TU"]);
            }
            else
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.PHUTTRHU_TU = null;
            }

            if(Entity.Tables[0].Rows[0]["NGAYTRTH_DEN"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.NGAYTRTH_DEN = Convert.ToDateTime(Entity.Tables[0].Rows[0]["NGAYTRTH_DEN"]);
            }
            else
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.NGAYTRTH_DEN = null;
            }

            if(Entity.Tables[0].Rows[0]["GIOTRHU_DEN"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.GIOTRHU_DEN = Convert.ToInt16(Entity.Tables[0].Rows[0]["GIOTRHU_DEN"]);
            }
            else
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.GIOTRHU_DEN = null;
            }

            if(Entity.Tables[0].Rows[0]["PHUTTRHU_DEN"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.PHUTTRHU_DEN = Convert.ToInt16(Entity.Tables[0].Rows[0]["PHUTTRHU_DEN"]);
            }
            else
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.PHUTTRHU_DEN = null;
            }           

            if (Entity.Tables[0].Rows[0]["NGUOI_TAO"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.NGUOI_TAO = Entity.Tables[0].Rows[0]["NGUOI_TAO"].ToString();
            }
            else
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.NGUOI_TAO = null;
            }

            if (Entity.Tables[0].Rows[0]["NGAY_TAO"].ToString() != string.Empty)
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.NGAY_TAO = Convert.ToDateTime(Entity.Tables[0].Rows[0]["NGAY_TAO"]);
            }
            else
            {
                this.obj_NPC_TRTH_DDO_Controller.pInfor.NGAY_TAO = null;
            }

            this.obj_NPC_TRTH_DDO_Controller.pInfor.TG_MDIEN_CANCU = Convert.ToDecimal(Entity.Tables[0].Rows[0]["TG_MDIEN_CANCU"]);
            this.obj_NPC_TRTH_DDO_Controller.pInfor.TG_MDIEN_TRTHU = Convert.ToDecimal(Entity.Tables[0].Rows[0]["TG_MDIEN_TRTHU"]);
            this.obj_NPC_TRTH_DDO_Controller.pInfor.CHUOI_GIA = Entity.Tables[0].Rows[0]["CHUOI_GIA"].ToString();
            this.obj_NPC_TRTH_DDO_Controller.pInfor.THANH_TIEN = Convert.ToDecimal(Entity.Tables[0].Rows[0]["THANH_TIEN"]);
            this.obj_NPC_TRTH_DDO_Controller.pInfor.THANH_TIEN_TRU_SLTHAO = Convert.ToDecimal(Entity.Tables[0].Rows[0]["THANH_TIEN_TRU_SLTHAO"]);

        }

        #endregion
    }
}
